<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="__PUBLIC__/layui/css/layui.css"  media="all">
    <link rel="stylesheet" href="__PUBLIC__/font-awesome/css/font-awesome.min.css" media="all" />
    <link rel="stylesheet" href="__CSS__/admin.css"  media="all">
    <script src="{$Think.config.httpFlag}{$Think.config.google_map_url}" async="async"></script>
    <style>
        .box{
            margin-top:20px;
            margin-bottom:10px;
        }
        #productPricing tr th,td{
            text-align:center
        }
        .required_text{
           color:red;
            padding: 8px;
        }
        table tr td{text-align: left}
        #addclassify {
            display: inline-block;
            width: 40px;
            height: 40px;
            border: 1px solid #666;
            line-height: 40px;
            border-radius: 40px;
            text-align: center;
            cursor: pointer;
            margin-top: 20px;
        }
    </style>
</head>
<body>

<div style="padding: 20px; background-color: #F2F2F2;">
    <div class="layui-row layui-col-space15">
        <!--基础信息-->
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-header">
                    <h2>价格计算</h2>
                </div>
                <div class="layui-card-body">
                    <div class="box">
                        <div style="margin-left:20px;">
                            <form class="layui-form" id="basic">
                                <div class="layui-form-item">
                                    <label class="layui-form-label">包车利率</label>
                                    <div class="layui-input-inline" style="width: 700px">
                                        <input name="vehicle_rate" lay-verify="required" {notempty name="$goods.vehicle_rate"}value="{$goods.vehicle_rate}"{/notempty} placeholder="请输入包车利率" autocomplete="off" class="layui-input" type="text">
                                    </div>
                                </div>
                                <div class="layui-form-item">
                                    <label class="layui-form-label">门票利率</label>
                                    <div class="layui-input-inline" style="width: 700px">
                                        <input name="ticket_rate" lay-verify="required" {notempty name="$goods.ticket_rate"}value="{$goods.ticket_rate}"{/notempty} placeholder="请输入包车利率" autocomplete="off" class="layui-input" type="text">
                                    </div>
                                </div>
                                <div class="layui-form-item">
                                    <label class="layui-form-label">酒店利率</label>
                                    <div class="layui-input-inline" style="width: 700px">
                                        <input name="hotel_rate" lay-verify="required" {notempty name="$goods.hotel_rate"}value="{$goods.hotel_rate}"{/notempty} placeholder="请输入包车利率" autocomplete="off" class="layui-input" type="text">
                                    </div>
                                </div>

                                <div class="layui-form-item">
                                    <label class="layui-form-label">门票总价</label>
                                    <div class="layui-input-inline" style="width: 700px">
                                        <input name="ticket_cost" lay-verify="required"  placeholder="门票总价" autocomplete="off" class="layui-input" type="text">
                                    </div>
                                </div>
                                <div class="layui-form-item">
                                    <label class="layui-form-label">用车总价</label>
                                    <div class="layui-input-inline" style="width: 700px">
                                        <input name="vehicle_cost" lay-verify="required"  placeholder="用车总价" autocomplete="off" class="layui-input" type="text">
                                    </div>
                                </div>
                                <div class="layui-form-item">
                                    <label class="layui-form-label">酒店总价/晚</label>
                                    <div class="layui-input-inline" style="width: 700px">
                                        <input name="hotel_cost" lay-verify="required"  placeholder="酒店总价" autocomplete="off" class="layui-input layui-input-inline" type="text">
                                        <span class="layui-input-inline" style="line-height: 40px;width:2%">x</span>
                                        <input name="days" lay-verify="required"  placeholder="入住天数" autocomplete="off" class="layui-input layui-input-inline" type="text">
                                        <span class="layui-input-inline" style="line-height: 40px;">晚</span>
                                    </div>
                                </div>
                                <div class="layui-form-item">
                                    <label class="layui-form-label">汇率</label>
                                    <div class="layui-input-inline" style="width: 700px">
                                        {volist name="exchange_rate" id="value"}
                                        <input type="radio" name="currency_rate" value="{$value['exchange_rate']}" title="{$value['name']}">
                                        {/volist}
                                    </div>
                                </div>

                                <div class="layui-form-item">
                                    <label class="layui-form-label">总人数</label>
                                    <div class="layui-input-inline" style="width: 700px">
                                        <input name="people_num" lay-verify="required"  placeholder="总人数" autocomplete="off" class="layui-input" type="text">
                                    </div>
                                </div>
                                <div class="layui-form-item">
                                    <label class="layui-form-label">核算公式【总价】</label>
                                    <div class="layui-input-inline" style="width: 700px">
                                        <input name="expression"  placeholder="" autocomplete="off" class="layui-input" type="text">
                                    </div>
                                </div>
                                <div class="layui-form-item">
                                    <label class="layui-form-label">单价</label>
                                    <div class="layui-input-inline" style="width: 700px">
                                        <input name="unitPrice"  placeholder="" autocomplete="off" class="layui-input" type="text">
                                    </div>
                                </div>
                                <div class="layui-form-item">
                                    <label class="layui-form-label">总价</label>
                                    <div class="layui-input-inline" style="width: 700px">
                                        <input name="totalPrice"  placeholder="" autocomplete="off" class="layui-input" type="text">
                                    </div>
                                </div>

                                <div class="layui-form-item">
                                    <div class="layui-input-block">
                                        <a class="layui-btn layui-btn-radius calculatePriceBtn" lay-submit lay-filter="basic">计算</a>
                                    </div>
                                </div>

                            </form>
                        </div>
                    </div>
                </div>
            </div>
        </div>

    </div>
</div>


<script src="__PUBLIC__/layui/layui.js"></script>
<script src="__PUBLIC__/jquery/jquery.min.js"></script>
<script>
    layui.use(['element','layer', 'form'], function() {
        var layer = layui.layer,
            element = layui.element,
            $ = layui.jquery,
            form = layui.form;
        //***************************************************************************
        $(".calculatePriceBtn").click(function(){
            var vehicle_rate = checkParam("vehicle_rate");
            var hotel_rate = checkParam("hotel_rate");
            var ticket_rate = checkParam("ticket_rate");
            var vehicle_cost = checkParam("vehicle_cost");
            var days= checkParam("days");
            var hotel_cost = checkParam("hotel_cost");
            var ticket_cost = checkParam("ticket_cost");
            var people_num = checkParam("people_num");

            var totalPrice = vehicle_rate*vehicle_cost+ticket_rate*ticket_cost*people_num+hotel_rate*hotel_cost*days;

            var exchange = $("input[name=currency_rate]:checked").val();
            console.log(exchange);

            totalPrice = totalPrice*exchange;
            var unitPrice = totalPrice/people_num;

            var expression = "("+vehicle_rate+" * "+vehicle_cost+" + "+ticket_rate+" * "+ticket_cost+" + "+hotel_rate+" * "+hotel_cost+" * "+days+") * "+exchange;

            $("input[name=expression]").val(expression);
            $("input[name=totalPrice]").val(totalPrice);
            $("input[name=unitPrice]").val(unitPrice);
        })

        function checkParam(name)
        {
            var value = $("input[name="+name+"]").val();
            if(value=="" || value==undefined){
                return false;
            }else{
                return parseFloat(value);
            }
        }
    });
</script>
</body>
</html>
